package com.java.goods.mapper;

import com.java.goods.entity.Goods;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * <p>
 * 商品表 Mapper 接口
 * </p>
 *
 * @author jiangli
 * @since 2019-12-15
 */
public interface GoodsMapper extends BaseMapper<Goods> {

	/**
	 * 通过分类id查询该分类下的商品
	 */
	@Select("select a.id as id ,a.title as title ,a.sell_point as sellPoint, a.price as price,a.num as num,a.barcode as barcode,a.image as image ,a.parent_id as parentId,a.cid as cid,a.status as status,a.created as created,a.updated as updated from goods as a inner join  goods_category as b on a.parent_id=b.id where b.id =#{id} LIMIT 0,8")
	List<Goods> getIndexItem(@Param("id") Long id);

	/**
	 * 通过商品id查询商品
	 */
	@Select("select a.id as id ,a.title as title ,a.sell_point as sellPoint, a.price as price,a.num as num,a.barcode as barcode,a.image as image ,a.parent_id as parentId,a.cid as cid,a.status as status,a.created as created,a.updated as updated from goods as a where a.id =#{id}")
	Goods getItem(@Param("id") Long id);
}
